home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2005 October / PCWOCT05.iso / Software / FromTheMag / XAMPP 1.4.14 / xampp-win32-1.4.14-installer.exe / xampp / php / pear / Log / display.php < prev    next >
PHP Script  |  2004-10-01  |  3KB  |  109 lines

  1. <?php
  2. /**
  3.  * $Header: /repository/pear/Log/Log/display.php,v 1.5 2004/01/19 08:02:40 jon Exp $
  4.  *
  5.  * @version $Revision: 1.5 $
  6.  * @package Log
  7.  */
  8.  
  9. /**
  10.  * The Log_display class is a concrete implementation of the Log::
  11.  * abstract class which writes message into browser in usual PHP maner.
  12.  * This may be useful because when you use PEAR::setErrorHandling in
  13.  * PEAR_ERROR_CALLBACK mode error messages are not displayed by
  14.  * PHP error handler.
  15.  *
  16.  * @author  Paul Yanchenko <pusher@inaco.ru>
  17.  * @since   Log 1.8.0
  18.  * @package Log
  19.  *
  20.  * @example display.php     Using the display handler.
  21.  */
  22. class Log_display extends Log
  23. {
  24.     /**
  25.      * String to output before an error message
  26.      * @var string
  27.      * @access private
  28.      */
  29.     var $_error_prepend = '';
  30.  
  31.     /**
  32.      * String to output after an error message
  33.      * @var string
  34.      * @access private
  35.      */
  36.     var $_error_append = '';
  37.  
  38.  
  39.     /**
  40.      * Constructs a new Log_display object.
  41.      *
  42.      * @param string $name     Ignored.
  43.      * @param string $ident    The identity string.
  44.      * @param array  $conf     The configuration array.
  45.      * @param int    $level    Log messages up to and including this level.
  46.      * @access public
  47.      */
  48.     function Log_display($name = '', $ident = '', $conf = array(),
  49.                          $level = PEAR_LOG_DEBUG)
  50.     {
  51.         $this->_id = md5(microtime());
  52.         $this->_ident = $ident;
  53.         $this->_mask = Log::UPTO($level);
  54.  
  55.         if (!empty($conf['error_prepend'])) {
  56.             $this->_error_prepend = $conf['error_prepend'];
  57.         } else {
  58.             $this->_error_prepend = ini_get('error_prepend_string');
  59.         }
  60.  
  61.         if (!empty($conf['error_append'])) {
  62.             $this->_error_append = $conf['error_append'];
  63.         } else {
  64.             $this->_error_append = ini_get('error_append_string');
  65.         }
  66.     }
  67.  
  68.     /**
  69.      * Writes $message to the text browser. Also, passes the message
  70.      * along to any Log_observer instances that are observing this Log.
  71.      *
  72.      * @param mixed  $message    String or object containing the message to log.
  73.      * @param string $priority The priority of the message.  Valid
  74.      *                  values are: PEAR_LOG_EMERG, PEAR_LOG_ALERT,
  75.      *                  PEAR_LOG_CRIT, PEAR_LOG_ERR, PEAR_LOG_WARNING,
  76.      *                  PEAR_LOG_NOTICE, PEAR_LOG_INFO, and PEAR_LOG_DEBUG.
  77.      * @return boolean  True on success or false on failure.
  78.      * @access public
  79.      */
  80.     function log($message, $priority = null)
  81.     {
  82.         /* If a priority hasn't been specified, use the default value. */
  83.         if ($priority === null) {
  84.             $priority = $this->_priority;
  85.         }
  86.  
  87.         /* Abort early if the priority is above the maximum logging level. */
  88.         if (!$this->_isMasked($priority)) {
  89.             return false;
  90.         }
  91.  
  92.         /* Extract the string representation of the message. */
  93.         $message = $this->_extractMessage($message);
  94.  
  95.         /* Build and output the complete log line. */
  96.         echo $this->_error_prepend .
  97.              '<b>' . ucfirst($this->priorityToString($priority)) . '</b>: '.
  98.              htmlspecialchars($message) .
  99.              $this->_error_append . "<br />\n";
  100.  
  101.         /* Notify observers about this log message. */
  102.         $this->_announce(array('priority' => $priority, 'message' => $message));
  103.  
  104.         return true;
  105.     }
  106. }
  107.  
  108. ?>
  109.